// myviews/myinfo/myinfo.js
var url = require("../../utils/servicePath.js")
var alert = require("../../utils/alert.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    AP0200:"",
    sexItems: [
      { name: '男', value: '1' },
      { name: '女', value: '2' }
    ],
    AP0201: "",//姓名
    AP0202: "",//性别
    AP0203: "",//职业
    AP0204: "",//籍贯
    AP0205: "",//年龄
    AP0206: "",//住址
    AP0207: "",//现病史
    AP0208: "",//既往史
    AP0209: "",//家族史
    AP0210: "",//个人生活史
    AP0211: "",//血压
    AP0212: ""//血糖

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var backUserInfo = getApp().globalData.backUserInfo;

    this.setData({
      AP0200: backUserInfo.syS0100
    })
    console.log(this.data.AP0200)
    var _this = this;
    wx.request({
      url: url.RegisterService() + "?userId=" + backUserInfo.syS0100,
      method:"GET",
      success:function(res){
        console.log(res);
        if(res.data.code == 200){
          _this.setData({
            AP0200:res.data.condition.aP0200,
            AP0201: res.data.condition.aP0201,//姓名
            AP0202: res.data.condition.aP0202,//性别
            AP0203: res.data.condition.aP0203,//职业
            AP0204: res.data.condition.aP0204,//籍贯
            AP0205: res.data.condition.aP0205,//年龄
            AP0206: res.data.condition.aP0206,//住址
            AP0207: res.data.condition.aP0207,//现病史
            AP0208: res.data.condition.aP0208,//既往史
            AP0209: res.data.condition.aP0209,//家族史
            AP0210: res.data.condition.aP0210,//个人生活史
            AP0211: res.data.condition.aP0211,//血压
            AP0212: res.data.condition.aP0212//血糖
          })
        }

        var sexItems = _this.data.sexItems;
        for (var i = 0, len = sexItems.length; i < len; ++i) {
          sexItems[i].checked = sexItems[i].value == res.data.condition.aP0202;
        }

        _this.setData({
          sexItems: sexItems
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value);

    var sexItems = this.data.sexItems;
    for (var i = 0, len = sexItems.length; i < len; ++i) {
      sexItems[i].checked = sexItems[i].value == e.detail.value;
    }

    this.setData({
      AP0202: e.detail.value,
      sexItems: sexItems
    });
  },
  //姓名
  AP0201Change: function (e) {
    this.setData({
      AP0201: e.detail.value
    })
  },
  AP0205Input: function (e) {
    this.setData({
      AP0205: e.detail.value
    })
  },
  AP0203Input: function (e) {
    this.setData({
      AP0203: e.detail.value
    })
  },
  AP0204Input: function (e) {
    this.setData({
      AP0204: e.detail.value
    })
  },
  AP0212Input: function (e) {
    this.setData({
      AP0212: e.detail.value
    })
  },
  AP0211Input: function (e) {
    this.setData({
      AP0211: e.detail.value
    })
  },
  AP0206Input: function (e) {
    this.setData({
      AP0206: e.detail.value
    })
  },
  AP0207Input: function (e) {
    this.setData({
      AP0207: e.detail.value
    })
  },
  AP0208Input: function (e) {
    this.setData({
      AP0208: e.detail.value
    })
  },
  AP0209Input: function (e) {
    this.setData({
      AP0209: e.detail.value
    })
  },
  saveInfo: function () {
    console.log(this.data)
    var _this = this;
    wx.request({
      url: url.RegisterService(),
      method: "PUT",
      data: {
        AP0201: _this.data.AP0201,//姓名
        AP0202: _this.data.AP0202,//性别
        AP0203: _this.data.AP0203,//职业
        AP0204: _this.data.AP0204,//籍贯
        AP0205: _this.data.AP0205,//年龄
        AP0206: _this.data.AP0206,//住址
        AP0207: _this.data.AP0207,//现病史
        AP0208: _this.data.AP0208,//既往史
        AP0209: _this.data.AP0209,//家族史
        AP0210: _this.data.AP0210,//个人生活史
        AP0211: _this.data.AP0211,//血压
        AP0212: _this.data. AP0212,//血糖
        AP0200: _this.data.AP0200
      },
      success:function(res){
        if(res.data.code == 200){
          alert.toast("保存成功")
        }else{
          alert.toast("保存失败，请稍后再试")
        }
      }
    })
  }
})